package Exercise;
//金额转换

import java.util.Scanner;
public class String_2 {
    public static void main(String[] args) {
        //键盘录入
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个整数：");
        int money;
        while (true) {
            money = sc.nextInt();
            //合法性检验
            if (money >= 0 && money <= 9999999) {
                break;
            } else {
                System.out.println("错误，请重新输入！");
            }
        }
        //取出每一位
        int count =0;  //统计需要补零的个数
        String res = "";
        while(money>0){
            int flag = money %10;
            res = (Transfer(flag)) + res;  //将有效的数字转换
            money /= 10;
            count++;
        }
        //补上位数
        res = Adds(res, count);
        //插入单位并输出
        String[] danwei ={"佰","拾","万","仟","佰","拾","元"};
        for (int i = 0; i < 7; i++) {
            System.out.print(res.charAt(i));
            System.out.print(danwei[i]);
        }
    }

    //转化
    public static String Transfer(int num){
        String[] temp ={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        for (int i = 0; i < temp.length; i++) {
            if(i==num)
                return temp[i];
        }
        return "";
    }
    //补零
    public static String Adds(String sr,int count){
        int num = 7-count;
        for (int i = 0; i < num; i++) {
            sr = "零"+sr;
        }
        return sr;
    }
}
